﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DBFile.Providers;
using DBFile.AzureLocalStorageProvider.Impl;
using System.Collections.Specialized;
using DBFile.Core.Interfaces;

namespace DBFile.Providers
{
    public class AzureLocalStorageProvider : DBFileProviderBase
    {
        protected override string ProviderDescription
        {
            get { return ProviderDescriptionMessage; }
        }

        protected override void OnAfterInitialize(NameValueCollection configValue)
        {
            this.LocalStorageName = GetConfigSettingOrThrow(configValue, LocalStorageNameKey, LocalStorageNameMissingMessage);
        }

        protected override IDBFileProvider Provider
        {
            get
            {
                lock (padLock)
                {
                    if (_provider == null)
                    {
                        _provider = new LocalStorageClient(LocalStorageName);
                    }
                }
                return _provider;
            }
        }

        internal string LocalStorageName { get; private set; }
        internal bool UseCompression { get; private set; }

        private const string ProviderDescriptionMessage = "AzureLocalStorage DBFile Provider";
        private const string LocalStorageNameKey = "localStorageName";
        private const string LocalStorageNameMissingMessage = "Local Storage Name is not specified";
    }
}
